$(function(){
	$('#tt').datagrid({
		url:'/miguMusicConfig/getMiguMusicConfigListPage'
	});
	
});

function doAdd(){
	$('#addForm').form('clear');
	
	$('#versionId').val('6.2.2');
	$('#signVersionId').val('V001');
	$('#addWin').window('open');
}

function doEdit(){
	var record = $('#tt').datagrid('getSelected');
	if(record==null||record==''){
		$.messager.alert("提示", "请先选择一条记录");
		return;
	}
	
	$('#idId').val(record.id);
	$('#nameId').val(record.name);
	$('#totalNumId').val(record.totalNum);
	$('#channelIdId').val(record.channelId);
	$('#userRateId').val(record.userRate);
	$('#subChannelIdId').val(record.subChannelId);
	$('#versionId').val(record.version);
	$('#signVersionId').val(record.signVersion);
	$('#packageSignatureId').val(record.packageSignature);
	
	$('#addWin').window('open');
}

function doCopy() {
	$('#addForm').form('clear');
	
	var row = $('#tt').datagrid('getSelections');
	if (row.length == 0) {
		showMsg(market.content.title, "请选择一条记录！", alert);
		return false;
	}
	if (row.length > 1) {
		showMsg(market.content.title, "复制操作只能选择一条记录！", alert);
		return false;
	}
	var record = row[0];
	
	$('#userRateId').val(record.userRate);
	$('#versionId').val(record.version);
	$('#signVersionId').val(record.signVersion);
	$('#packageSignatureId').val(record.packageSignature);
	
	$('#addWin').window('open');
}

function doStatus(status){
	
	var record = $('#tt').datagrid('getSelected');
	if(record==null||record==''){
		$.messager.alert("提示", "请先选择一条记录");
		return;
	}
	
	var msg="你确定要启动吗？";
	if(status=='2'){
		msg="你确定要作废吗？";
	}
	
	$.messager.confirm('提示',msg, function(opt){
		if (opt){
			var miguMusicConfigId=record.id;
			$.ajax({
				url: '/miguMusicConfig/updateMiguMusicStatus',
				type: 'POST',
				data : {
		            id:miguMusicConfigId,
		            status:status
				},
				success : function(data) {
					if (data.return_code == '1') {
						$.messager.alert(market.content.title, "删除成功");
						$("#tt").datagrid('reload');
						$('#tt').datagrid('unselectAll');
					} else {
						$.messager.alert(market.content.title, data.return_msg);
					}
				},
				error : function(e) {
					$.messager.alert("未知错误");
				}
			})
		}
	});
	
}

function doDel(){
	var record = $('#tt').datagrid('getSelected');
	if(record==null||record==''){
		$.messager.alert("提示", "请先选择一条记录");
		return;
	}
	
	
	$.messager.confirm('提示', '你确定要删除吗？', function(opt){
		if (opt){
			var miguMusicConfigId=record.id;
			$.ajax({
				url: '/miguMusicConfig/deleteMiguMusicConfig',
				type: 'POST',
				data : {
		            id:miguMusicConfigId
				},
				success : function(data) {
					if (data.return_code == '1') {
						$.messager.alert(market.content.title, "删除成功");
						$("#tt").datagrid('reload');
						$('#tt').datagrid('unselectAll');
					} else {
						$.messager.alert(market.content.title, data.return_msg);
					}
				},
				error : function(e) {
					$.messager.alert("未知错误");
				}
			})
		}
	});
}

function doSearch(){
	
	var sname=$('#snameId').val();
	var status=$('#sstatusId').combobox('getValue');
	
	$('#tt').datagrid({
		url:'/miguMusicConfig/getMiguMusicConfigListPage',
		queryParams:{
			sname:sname,
			status:status
		}
	});
	$('#tt').datagrid('unselectAll');
}

function save(){
	var id=$('#idId').val();
	var url='/miguMusicConfig/updateMiguMusicConfig';
	if(id==null||id==''){
		url='/miguMusicConfig/saveMiguMusicConfig';
	}
	
	$('#addForm').form('submit',{
		url : url,
		onSubmit : function() {
			var flag = $(this).form('validate');
			if (!flag) {
				return flag;
			}
			showProcess(true, market.content.title, market.content.submitting);
			return true;
		},
		success : function(data) {
			showProcess(false);
			var data = eval('(' + data + ')');
			if (data.return_code == '1') {
				$("#addWin").window('close');
				$('#tt').datagrid('reload');
				$('#tt').datagrid('unselectAll');
			} else {
				$.messager.alert(market.content.title, data.return_msg);
			}
		},
		onLoadError : function() {
			showProcess(false);
			$.messager.alert(market.content.title, market.content.networkError);
		}
	});
	
}

function cancel(){
	$('#addWin').window('close');
}

function statusFormatter(value){
	if(value=='0'){
		return '待启动';
	}if(value=='1'){
		return '启用';
	}else if(value=='2'){
		return '作废'
	}
}